﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Minestorm.Retro.Entities
{
    public class Dropship : Entity
    {
        public Dropship(GraphicsDevice graphics, Vector2 position)
            : base(graphics, position)
        {
            Scale = 1;
            Hidden = false;
        }

        public override void Initialize()
        {
            var verticies = new VertexPositionColor[28];
            verticies[0] = new VertexPositionColor(new Vector3(10, 2, 0), Constants.VectorColor);
            verticies[1] = new VertexPositionColor(new Vector3(30, -8, 0), Constants.VectorColor);
            verticies[2] = new VertexPositionColor(new Vector3(17, -13, 0), Constants.VectorColor);
            verticies[3] = new VertexPositionColor(new Vector3(12, -11, 0), Constants.VectorColor);
            verticies[4] = new VertexPositionColor(new Vector3(13, -3, 0), Constants.VectorColor);
            verticies[5] = new VertexPositionColor(new Vector3(13, -2, 0), Constants.VectorColor);
            verticies[6] = new VertexPositionColor(new Vector3(10, -2, 0), Constants.VectorColor);
            verticies[7] = new VertexPositionColor(new Vector3(10, -3, 0), Constants.VectorColor);
            verticies[8] = new VertexPositionColor(new Vector3(9, -11, 0), Constants.VectorColor);
            verticies[9] = new VertexPositionColor(new Vector3(-9, -11, 0), Constants.VectorColor);
            verticies[10] = new VertexPositionColor(new Vector3(-10, -3, 0), Constants.VectorColor);
            verticies[11] = new VertexPositionColor(new Vector3(-10, -2, 0), Constants.VectorColor);
            verticies[12] = new VertexPositionColor(new Vector3(-13, -2, 0), Constants.VectorColor);
            verticies[13] = new VertexPositionColor(new Vector3(-13, -3, 0), Constants.VectorColor);
            verticies[14] = new VertexPositionColor(new Vector3(-12, -11, 0), Constants.VectorColor);
            verticies[15] = new VertexPositionColor(new Vector3(-17, -13, 0), Constants.VectorColor);
            verticies[16] = new VertexPositionColor(new Vector3(-30, -8, 0), Constants.VectorColor);
            verticies[17] = new VertexPositionColor(new Vector3(-10, 2, 0), Constants.VectorColor);


            verticies[18] = new VertexPositionColor(new Vector3(-12, -10, 0), Constants.VectorColor);
            verticies[19] = new VertexPositionColor(new Vector3(12, -10, 0), Constants.VectorColor);

            verticies[20] = new VertexPositionColor(new Vector3(-9, -10, 0), Constants.VectorColor);
            verticies[21] = new VertexPositionColor(new Vector3(9, -10, 0), Constants.VectorColor);

            verticies[22] = new VertexPositionColor(new Vector3(8, 1, 0), Constants.VectorColor);
            verticies[23] = new VertexPositionColor(new Vector3(8, -1, 0), Constants.VectorColor);
            verticies[24] = new VertexPositionColor(new Vector3(-8, -1, 0), Constants.VectorColor);
            verticies[25] = new VertexPositionColor(new Vector3(-8, 1, 0), Constants.VectorColor);
            verticies[26] = new VertexPositionColor(new Vector3(7, -1, 0), Constants.VectorColor);
            verticies[27] = new VertexPositionColor(new Vector3(-7, -1, 0), Constants.VectorColor);


            SetVerticies(verticies);

            SetIndicies("ship", false,
                0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 0,
                1, 4,
                16, 13,
                7, 10,
                18, 20,
                19, 21,
                18, 14,
                19, 3,
                18, 12,
                19, 4,
                22, 23, 23, 24, 24, 25, 25, 22,
                22, 26,
                25, 27
            );
        }

        public float Scale { get; set; }

        public override Matrix GetWorld(string indexBufferName)
        {
            return Matrix.Identity * Matrix.CreateScale(Scale) * Matrix.CreateTranslation(new Vector3(Position, 0f));
        }
    }
}
